//
//  PatchMeshSystem.cpp
//  Cubism
//
//  Created by Jeppe Nielsen on 7/17/14.
//  Copyright (c) 2014 Jeppe Nielsen. All rights reserved.
//

#include "PatchMeshSystem.hpp"
#include "MathHelper.hpp"

void PatchMeshSystem::Initialize() {
    AddComponent<Patch>();
    AddComponent<Mesh>();
}

void PatchMeshSystem::ObjectAdded(Nano::GameObject *object) {
    CreateMesh(object->GetComponent<Patch>(), object->GetComponent<Mesh>());
}

void PatchMeshSystem::ObjectRemoved(Nano::GameObject *object) {
    
}

void PatchMeshSystem::CreateMesh(Patch* patch, Nano::Mesh *mesh) {
    
    
    
    Mesh::VerticesList& vertices = mesh->Vertices();
    Mesh::TrianglesList& triangles = mesh->Triangles();
    
    vertices.clear();
    triangles.clear();
    
    
    vertices.push_back(Vertex({1.5f, 1.5f, -0.5f}, Colour::Black()));
    vertices.push_back(Vertex({-1.5f, 1.5f, -0.5f}, Colour::Black()));
    vertices.push_back(Vertex({-1.5f, -1.5f, -0.5f}, Colour(84,84,84)));
    vertices.push_back(Vertex({1.5f, -1.5f, -0.5f}, Colour(84,84,84)));
    
    triangles.push_back((short)0);
    triangles.push_back((short)1);
    triangles.push_back((short)2);

    triangles.push_back((short)0);
    triangles.push_back((short)2);
    triangles.push_back((short)3);
    
    
    
        
    
}